$(function () {
    //返回主页按钮监听事件
    $("#back").click(function () {
        window.history.back(-1);
    });
    //动态生成所有信息
    $.ajax({
        url:"/hospital/record/register/get/patient",
        type:"GET",
        dataType:"json",
        success:function (data){
            $(".statusInfo1").html("");
            $.each(data,function (index,ele) {
                $(".statusInfo1").append(" <div class=\"statusInfo\" id="+ele.id+">\n" +
                    "       <li>\n" +
                    "        <i class=\"layui-icon layui-icon-username\" style=\"font-size: 80px; color: rgba(0,0,0,0.96);\"></i>\n" +
                    "        <div class=\"in\">\n" +
                    "            <label>姓名：<input placeholder="+ele.patName+" class=\"inInfo\" value=\"\"></label>\n" +
                    "            <label>性别：<input placeholder="+ele.patSex+" class=\"inInfo\" value=\"\"></label>\n" +
                    "            <label>年龄：<input placeholder="+ele.patAge+" class=\"inInfo\" value=\"\"></label>\n" +
                    "            <label>科室：<input placeholder="+ele.patOfcName+" class=\"inInfo\" value=\"\"></label>\n" +
                    "        </div>\n" +
                    "       </li>\n" +
                    "    </div>")
            });
        },
        error:function () {
            layui.use('layer', function(){
                var layer = layui.layer;
                layer.msg('数据获取失败！', {
                    time: 1500, //1.5s后自动关闭
                });
            });
        }
    })
    //监听动态div的点击事件
    $(".statusInfo1").on("click",".statusInfo",function () {
        alert(this.id);
        var id=this.id;
            $.ajax({
                url: "/hospital/record/get/info",
                type: "post",
                contentType: "application/json;charset=utf-8",
                dataType: "json",
                data:JSON.stringify({
                    "id":id
                }),
                success:function (data) {
                    console.log(data.patConven);
                        $("#show-num4").val(data.patConven);
                        $("#show-name4").val(data.patName);
                        $("#show-age4").val(data.patAge);
                        $("#show-sex4").val(data.patSex);
                        $("#show-id4").val(data.patRemark);
                        $("#show-office4").val(data.patOfcName);
                        $("#show-contact4").val(data.patContact);

                }
            });
        layui.use('layer', function(){
            var layer = layui.layer;
            layer.open({
                type: 1,
                area: ['400px', '500px'],
                content: $('#printInfo3') //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
            });
        });
        $("#register-update").click(function () {
            var patName=$("#show-name4").val();
            var patSex=$("#show-sex4").val();
            if(patSex=="男")
                patSex=1;
            else
                patSex=0;
            var patAge=$("#show-age4").val();
            var patRemark=$("#show-id4").val();
            var patContact=$("#show-contact4").val();
            $.ajax({
                url: "/hospital/patient/update/patient",
                type: "post",
                contentType: "application/json;charset=utf-8",
                dataType: "json",
                data:JSON.stringify({
                    "id":id,
                    "patName":patName,
                    "patSex":patSex,
                    "patAge":patAge,
                    "patRemark":patRemark,
                    "patContact":patContact
                }),
                success:function () {
                    layui.use('layer', function(){
                        var layer = layui.layer;
                        layer.msg('信息修改成功！', {
                            time: 1500, //1.5s后自动关闭
                        });
                    });
                },
                error:function () {
                    layui.use('layer', function(){
                        var layer = layui.layer;
                        layer.msg('信息修改失败！', {
                            time: 1500, //1.5s后自动关闭
                        });
                    });
                }
            })
                });
        //删除按钮监听事件
        $("#register-cancel").click(function () {
            $.ajax({
                url: "/hospital/patient/delete/patient",
                type: "post",
                contentType: "application/json;charset=utf-8",
                dataType: "json",
                data:JSON.stringify({
                    "id":id,
                }),
                success:function () {
                    layui.use('layer', function(){
                        var layer = layui.layer;
                        layer.msg('删除成功！', {
                            time: 1500, //1.5s后自动关闭
                        });
                    });
                },
                error:function () {
                    layui.use('layer', function(){
                        var layer = layui.layer;
                        layer.msg('删除失败！', {
                            time: 1500, //1.5s后自动关闭
                        });
                    });
                }
            })
        });
    });
    $('input:radio[name="sex"]').change(function(){
        if($(this).is(":checked")){
            var value=$(this).attr("value");
            $.ajax({
                url: "/hospital/record/get/info1",
                type: "post",
                contentType: "application/json;charset=utf-8",
                dataType: "json",
                data:JSON.stringify({
                    "patStatus":value
                }),
                success:function (data) {
                    $(".statusInfo1").html("");
                    $.each(data,function (index,ele) {
                        $(".statusInfo1").append(" <div class=\"statusInfo\" id="+ele.id+">\n" +
                            "       <li>\n" +
                            "        <i class=\"layui-icon layui-icon-username\" style=\"font-size: 80px; color: rgba(0,0,0,0.96);\"></i>\n" +
                            "        <div class=\"in\">\n" +
                            "            <label>姓名：<input placeholder="+ele.patName+" class=\"inInfo\" value=\"\"></label>\n" +
                            "            <label>性别：<input placeholder="+ele.patSex+" class=\"inInfo\" value=\"\"></label>\n" +
                            "            <label>年龄：<input placeholder="+ele.patAge+" class=\"inInfo\" value=\"\"></label>\n" +
                            "            <label>科室：<input placeholder="+ele.patOfcName+" class=\"inInfo\" value=\"\"></label>\n" +
                            "        </div>\n" +
                            "       </li>\n" +
                            "    </div>")
                    });
                },
                error:function () {
                    layui.use('layer', function(){
                        var layer = layui.layer;
                        layer.msg('数据获取失败！', {
                            time: 1500, //1.5s后自动关闭
                        });
                    });
                }
            })
            if(value==0){
                $.ajax({
                    url:"/hospital/record/register/get/patient",
                    type:"GET",
                    dataType:"json",
                    success:function (data){
                        $(".statusInfo1").html("");
                        $.each(data,function (index,ele) {
                            $(".statusInfo1").append(" <div class=\"statusInfo\" id="+ele.id+">\n" +
                                "       <li>\n" +
                                "        <i class=\"layui-icon layui-icon-username\" style=\"font-size: 80px; color: rgba(0,0,0,0.96);\"></i>\n" +
                                "        <div class=\"in\">\n" +
                                "            <label>姓名：<input placeholder="+ele.patName+" class=\"inInfo\" value=\"\"></label>\n" +
                                "            <label>性别：<input placeholder="+ele.patSex+" class=\"inInfo\" value=\"\"></label>\n" +
                                "            <label>年龄：<input placeholder="+ele.patAge+" class=\"inInfo\" value=\"\"></label>\n" +
                                "            <label>科室：<input placeholder="+ele.patOfcName+" class=\"inInfo\" value=\"\"></label>\n" +
                                "        </div>\n" +
                                "       </li>\n" +
                                "    </div>")
                        });
                    },
                    error:function () {
                        layui.use('layer', function(){
                            var layer = layui.layer;
                            layer.msg('数据获取失败！', {
                                time: 1500, //1.5s后自动关闭
                            });
                        });
                    }
                })
            }
            }
            // alert($(this).attr("value"));
    });

    //修改按钮监听事件

});